package comgame.scenes;

import java.util.HashMap;
import java.util.Map;

/**
 * 关卡数据类，管理关卡信息
 */
public class LevelData {
    private static LevelData instance;
    private Map<Integer, Boolean> unlockedLevels = new HashMap<>();
    private Map<Integer, LevelInfo> levelInfos = new HashMap<>();
    
    private LevelData() {
        // 初始化关卡信息
        initializeLevels();
    }
    
    public static LevelData getInstance() {
        if (instance == null) {
            instance = new LevelData();
        }
        return instance;
    }
    
    private void initializeLevels() {
        // 第一关默认解锁
        unlockedLevels.put(1, true);
        
        // 优化版怪物数值表（怪物名中文，掉落物不变）
        levelInfos.put(1, new LevelInfo(1, "史莱姆", 25, 28, 0, 1, 0.00, "普通剑", "铁剑"));
        levelInfos.put(2, new LevelInfo(2, "铁甲虫", 66, 43, 3, 2, 0.05, "铁剑", "金剑"));
        levelInfos.put(3, new LevelInfo(3, "妙蛙种子", 97, 58, 5, 4, 0.10, "金剑", "钻石剑"));
        levelInfos.put(4, new LevelInfo(4, "怨灵", 173, 77, 17, 18, 0.25, "钻石剑", "传说剑"));
        levelInfos.put(5, new LevelInfo(5, "蔬菜人", 237, 87, 37, 5, 0.15, "传说剑", "神器"));
        levelInfos.put(6, new LevelInfo(6, "南瓜王或常绿怪", 307, 96, 43, 30, 0.35, "神器", "终极武器"));
        levelInfos.put(7, new LevelInfo(7, "虚空领主", 412, 117, 57, 35, 0.40, "终极武器", "神秘物品"));
        // Boss关：世纪之花
        levelInfos.put(8, new LevelInfo(8, "世纪之花", 3000, 200, 50, 50, 0.5, "世纪之花掉落", "世纪之花稀有掉落"));
    }
    
    public boolean isLevelUnlocked(int level) {
        return unlockedLevels.getOrDefault(level, false);
    }
    
    public void unlockLevel(int level) {
        unlockedLevels.put(level, true);
    }
    
    public LevelInfo getLevelInfo(int level) {
        return levelInfos.get(level);
    }
    
    public int getMaxUnlockedLevel() {
        int maxLevel = 1;
        for (Map.Entry<Integer, Boolean> entry : unlockedLevels.entrySet()) {
            if (entry.getValue() && entry.getKey() > maxLevel) {
                maxLevel = entry.getKey();
            }
        }
        return maxLevel;
    }
    
    /**
     * 关卡信息类
     */
    public static class LevelInfo {
        private int level;
        private String monsterName;
        private int monsterHealth;
        private int monsterAttack;
        private int monsterDefense;
        private int monsterSpeed;
        private double monsterCritRate;
        private String dropItem1;
        private String dropItem2;
        
        public LevelInfo(int level, String monsterName, int monsterHealth, 
                       int monsterAttack, int monsterDefense, int monsterSpeed, double monsterCritRate,
                       String dropItem1, String dropItem2) {
            this.level = level;
            this.monsterName = monsterName;
            this.monsterHealth = monsterHealth;
            this.monsterAttack = monsterAttack;
            this.monsterDefense = monsterDefense;
            this.monsterSpeed = monsterSpeed;
            this.monsterCritRate = monsterCritRate;
            this.dropItem1 = dropItem1;
            this.dropItem2 = dropItem2;
        }
        
        // Getters
        public int getLevel() { return level; }
        public String getMonsterName() { return monsterName; }
        public int getMonsterHealth() { return monsterHealth; }
        public int getMonsterAttack() { return monsterAttack; }
        public int getMonsterDefense() { return monsterDefense; }
        public int getMonsterSpeed() { return monsterSpeed; }
        public double getMonsterCritRate() { return monsterCritRate; }
        public String getDropItem1() { return dropItem1; }
        public String getDropItem2() { return dropItem2; }
    }
    public void reset() {
        unlockedLevels.clear();      // 清空所有关卡解锁状态
        unlockedLevels.put(1, true); // 只解锁第一关
    }
} 